package com.peng.mapper;

import com.peng.pojo.ArticleType;
import com.peng.pojo.OpenCourse;
import com.peng.pojo.User;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

@Mapper
@Repository
public interface OpenCourseMapper {
    /**
     * 根据教师ID 查询相应的公开课信息
     *
     * @param teacherId
     * @return
     */
    @Select("select * from tb_open_course where teacher_id = #{teacherId}")
    List<OpenCourse> selectOpenCourseByteacherId(int teacherId);

    /**
     * 根据教师ID 查询公开课ID
     *
     * @param teacherId
     * @return
     */
    List<OpenCourse> selectOpenCourseIdByTeacherId(@Param("teacherId") Integer... teacherId);

    /**
     * 根据教师ID 删除公开课
     *
     * @param teacherId
     * @return
     */
    int deleteOpenCourseByTeacherId(@Param("teacherId") Integer... teacherId);

    /**
     * 根据公开课Id 删除所有相应课程资料信息
     *
     * @param courseId
     * @return
     */
    int delete0penResourcesByCourseId(@Param("courseId") Integer... courseId);

    /**
     * 根据公开课Id 删除所有参加该公开课用户信息
     *
     * @param courseId
     * @return
     */
    int deleteOpenSignByCourseId(@Param("courseId") Integer... courseId);

    /**
     * 根据教师ID 删除所有留言信息
     *
     * @param teacherId
     * @return
     */
    int deleteOpenTeacherComment(@Param("teacherId") Integer... teacherId);

    /**
     * 删除教师点赞
     *
     * @param teacherId
     * @return
     */
    int deleteTeacherThumbs(@Param("teacherId") Integer... teacherId);

    /**
     * 修改公开课状态
     *
     * @param status    1 正常，2冷冻，3假删除
     * @param teacherId 教师ID
     * @return
     */
    int updateOpenCourseStatus(@Param("status") int status, @Param("teacherId") Integer... teacherId);

    /**
     * 查询所有公开课信息
     *
     * @param name      公开课名称
     * @param teacherId 教师ID
     * @param typeId    课程分类ID
     * @return
     */
    List<OpenCourse> selectAllOpenCourse(@Param("name") String name,
                                         @Param("teacherId") Integer teacherId, @Param("typeId") Integer typeId);

    //查询用户姓名
    @Select("select real_name from tb_user where id = #{id}")
    User selectUserById(int id);

    //查询分类名称
    @Select("select * from tb_article_type where id = #{id}")
    ArticleType selectArticleTypeById(int id);

    /**
     * 根据公开课ID 修改公开课状态
     *
     * @param status 1正常 2关闭 3删除
     * @param id     公开课ID
     * @return
     */
    int updateOpenCourseStatusById(@Param("status") int status, @Param("id") Integer... id);

    /**
     * 查询最新公开课
     *
     * @return
     */
    @Select("select * from tb_open_course GROUP BY class_time desc limit 3")
    List<OpenCourse> selectOpenCourseClassTimeDesc();
}
